<table class="simulation">
    <tr>
        <td colspan="10" >
            <?php if (isset($_REQUEST["attacker_attack_level"])): ?>
            <a href="index.php?token_v1=<?php echo $token ?>">
                URL permanente de ce combat
            </a> -
            <span class="tinyurl">
                <a href="">
                </a>
            </span>
            <?php endif; ?>
        </td>
    </tr>
    <tr>
        <td colspan="10" class="$winner">
            <?php if ($winner == "attacker"): ?>
            <h2>Vous remportez la victoire !</h2>
            <h3>
                <?php $honnor_ratio = round((($def_raw_power / $att_raw_power) - 1) * 100, 2) ?>
                Vous gagnez <?php echo number_format(round($att_base_xp, 2), 2, ',', ' ') ?> XP <?php echo ($honnor_ratio > 0 ? '+ ' : ' ') . $honnor_ratio ?>%
                = <?php echo number_format(round($att_base_xp * ($def_raw_power / $att_raw_power)), 0, ',', ' ')?> XP
            </h3>
            <?php elseif ($winner == "defender"): ?>
            <h2>Vous perdez :(</h2>
            <?php else: ?>
            <h2>Match nul ^^</h2>
            <?php endif; ?>
        </td>
    </tr>
    <tr>
        <td />
        <td colspan="4" class="$winner">
            <h2>
                Puissance : <?php echo number_format($att_raw_power, 0, ',', ' ') ?>
            </h2>
        </td>
        <td />
        <td colspan="4" class="$winner">
            <h2>
                Puissance : <?php echo number_format($def_raw_power, 0, ',', ' ') ?>
            </h2>
        </td>
    </tr>
    <tr>
        <td>Tour</td>
        <td>Nom</td>
        <td>Type</td>
        <td>Puissance du Peloton</td>
        <td>Quantite</td>
        <td width="100px"></td>
        <td>Quantite</td>
        <td>Puissance du Peloton</td>
        <td>Type</td>
        <td>Nom</td>
    </tr>
    <?php $oddeven = "odd" ?>
    <?php $i = 0; foreach($result as $line): $i++ ?>
    <tr class="<?php echo ($oddeven = $oddeven == "odd" ? "even" : "odd")?>">
        <td class="turn">
            <?php echo $i ?>
        </td>
        <td>
            <?php echo $line['attacker']['name']?>
        </td>
        <td>
            <?php echo unit::type_to_name($line['attacker']['type'])?>
        </td>
        <td>
            <?php echo number_format($line['attacker']['before']['power'], 0, ',', ' ')?><br />
            <span class="result">
                <?php if ($sim->get_unit_type_bonus($line['attacker']['type'], $line['defender']['type'])): ?>
                bonus!<br />
                <?php endif; ?>
                <?php if($line['attacker']['after']['quantity'] ==
                    $line['attacker']['before']['quantity']): ?>
                &nbsp;
                <?php elseif ($line['attacker']['after']['quantity']): ?>
                -
                <?php
                echo number_format($line['attacker']['before']['power'] -
                    $line['attacker']['after']['power'], 0, ',', ' ')
                ?>
                <?php else: ?>
                &nbsp;
                <?php endif; ?>
            </span>
        </td>
        <td>
            <?php echo $line['attacker']['before']['quantity']?><br />
            <span class="result">
                <?php if($line['attacker']['overrun']): ?>
                overrun!
                <?php elseif ($line['attacker']['after']['quantity']): ?>
                -
                <?php
                echo $line['attacker']['before']['quantity'] -
                $line['attacker']['after']['quantity']
                ?>
                <?php else: ?>
                d&eacute;rout&eacute;!
                <?php endif; ?>
            </span>
        </td>
        <td></td>
        <td>
            <?php echo $line['defender']['before']['quantity']?><br />
            <span class="result">
                <?php if($line['defender']['overrun']): ?>
                overrun!
                <?php elseif ($line['defender']['after']['quantity']): ?>
                -
                <?php
                echo $line['defender']['before']['quantity'] -
                $line['defender']['after']['quantity']
                ?>
                <?php else: ?>
                d&eacute;rout&eacute;!
                <?php endif; ?>
            </span>
        </td>
        <td>
            <?php echo number_format($line['defender']['before']['power'], 0, ',', ' ')?><br />
            <span class="result">
                <?php if ($sim->get_unit_type_bonus($line['defender']['type'], $line['attacker']['type'])): ?>
                bonus!<br />
                <?php endif; ?>
                <?php if ($line['defender']['after']['quantity']): ?>
                -
                <?php
                echo number_format($line['defender']['before']['power'] -
                    $line['defender']['after']['power'], 0, ',', ' ')
                ?>
                <?php else: ?>
                &nbsp;
                <?php endif; ?>
            </span>
        </td>
        <td>
            <?php echo unit::type_to_name($line['defender']['type'])?>
        </td>
        <td>
            <?php echo $line['defender']['name']?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>
<script type="text/javascript">
    function set_tiny_url(data) {
        $(".tinyurl a").attr("href", data);
        $(".tinyurl a").html("TinyUrl");
        $(".tinyurl").append(' : ' + data);
    }
    $(document).ready(function() {
        if (tinyurl_ajax)
            tinyurl_ajax.abort();
        tinyurl_ajax = $.ajax({
            url : 'ajax_tinyurl.php' ,
            data : { URL : '<?php echo get_tiny_url($token) ?>'},
            success : set_tiny_url,
            type : 'GET'
        });
        });
        </script>
